package com.github.vortexdev.yachtclub.models;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Sergey Parakhin (sergey.parahin@gmail.com)
 */
public class Yacht {
    private int yachtId;
    private String name;
    private String hull;
    private String drive;
    private String purpose;
    private String description;
    private String contentType;
    private Owner owner;
    private List<Regatta> regattas = new LinkedList<Regatta>();
    private byte[] photo;

    public Yacht() {
    }

    public Yacht(int id) {
        this.yachtId = id;
    }

    public Yacht(int yachtId, String name, String hull, String drive,
                 String purpose, String description, Owner owner) {
        this.yachtId = yachtId;
        this.name = name;
        this.hull = hull;
        this.drive = drive;
        this.purpose = purpose;
        this.description = description;
        this.owner = owner;
    }

    public void setYachtId(int id) {
        this.yachtId = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getYachtId() {
        return yachtId;
    }

    public String getName() {
        return name;
    }

    public String getHull() {
        return hull;
    }

    public void setHull(String hull) {
        this.hull = hull;
    }

    public String getDrive() {
        return drive;
    }

    public void setDrive(String drive) {
        this.drive = drive;
    }

    public String getPurpose() {
        return purpose;
    }

    public void setPurpose(String purpose) {
        this.purpose = purpose;
    }

    public Owner getOwner() {
        return owner;
    }

    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    public byte[] getPhoto() {
        return photo;
    }

    public void setPhoto(byte[] photo) {
        this.photo = photo;
    }

    public List<Regatta> getRegattas() {
        return regattas;
    }

    public void addRegatta(Regatta regatta) {
        regattas.add(regatta);
        regatta.getYachts().add(this);
    }

    public String getOwnerName() {
        return owner != null ? owner.getName() : null;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null)
            return false;
        if (!(obj instanceof Yacht))
            return false;
        if (obj == this)
            return true;

        Yacht yacht = (Yacht) obj;

        return this.yachtId == yacht.yachtId && this.name.equals(yacht.name)
                && this.drive.equals(yacht.drive) && this.hull.equals(yacht.hull)
                && this.purpose.equals(yacht.purpose)
                && this.owner.getOwnerId() == yacht.getOwner().getOwnerId();
    }
}
